<?php
namespace soa\BasicInfo;

use soa\client;

class Branch extends client
{
    /**
     * 服务地址
     * @var string
     */
    public $service_url = 'http://core.kuaidihelp.com/';

    /**
     * 服务名称
     * @var string
     */
    protected $service_name = 'kuaidihelp_core';

    /**
     * 返回指定ID的上级网点编号
     * @param $indexShopId 网点快宝id
     * @param string $brand
     * @return bool|null|string
     */
    public function getParentBranchCodeById($indexShopId,$brand='')
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/getParentBranchCodeById';
            $param['index_shop_id'] = $indexShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return '';
    }

    /**
     * 返回指定网点编号的上级网点编号
     * @param $branchCode 网点编号
     * @param string $brand
     * @return bool|null|string
     */
    public function getParentBranchCodeByCode($branchCode,$brand='')
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/getParentBranchCodeByCode';
            $param['BranchCode'] = $branchCode;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return '';
    }

    /**
     * 返回指定ID的上级网点ID
     * @param $indexShopId 网点快宝id
     * @param string $brand
     * @return bool|null|string
     */
    public function getParentBranchIDById($indexShopId,$brand='')
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/getParentBranchIDById';
            $param['index_shop_id'] = $indexShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return '';
    }

    /**
     * 返回指定网点编号的上级网点ID
     * @param $branchCode 网点编号
     * @param string $brand
     * @return bool|null|string
     */
    public function getParentBranchIDByCode($branchCode,$brand='')
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/getParentBranchIDByCode';
            $param['BranchCode'] = $branchCode;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return '';
    }

    /**
     * 返回指定ID下面的子网点信息
     * @param $indexShopId 网点快宝id
     * @param string $brand
     * @param bool $sub
     * @return bool|null|string
     */
    public function getSubBranchesById($indexShopId,$brand='',$sub=false)
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/getSubBranchesById';
            $param['index_shop_id'] = $indexShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            if($sub)
                $param['sub'] = $sub;
            return $this->get($url, $param);
        }
        else
            return [];
    }


    /**
     * 返回指定网点编号下面的子网点信息
     * @param $branchCode 网点编号
     * @param string $brand
     * @param bool $sub
     * @return bool|null|string
     */
    public function getSubBranchesByCode($branchCode,$brand='',$sub=false)
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/getSubBranchesByCode';
            $param['BranchCode'] = $branchCode;
            if(!empty($brand))
                $param['brand'] = $brand;
            if($sub)
                $param['sub'] = $sub;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回指定ID的网点的官方信息
     * @param $indexShopId   网点快宝id
     * @param string $brand
     * @return array|bool|null
     */
    public function getBranchById($indexShopId,$brand='')
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/getBranchById';
            $param['index_shop_id'] = $indexShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回指定ID的网点的官方信息
     * @param $homeShopId   网点快宝homeshopid
     * @param string $brand
     * @return array|bool|null
     */
    public function getBranchByHomeId($homeShopId,$brand='')
    {
        if($homeShopId)
        {
            $url = 'v1/BasicInfo/getBranchByHomeId';
            $param['home_shop_id'] = $homeShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回指定网点编号的网点的官方信息
     * @param $branchCode   网点编号
     * @param string $brand
     * @return array|bool|null
     */
    public function getBranchByCode($branchCode,$brand='')
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/getBranchByCode';
            $param['BranchCode'] = $branchCode;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回指定ID的网点的网点编号
     * @param $indexShopId   网点快宝id
     * @param string $brand
     * @return array|bool|null
     */
    public function idToCode($indexShopId,$brand='')
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/idToCode';
            $param['index_shop_id'] = $indexShopId;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回指定网点编号的网点的Id
     * @param $branchCode   网点编号
     * @param string $brand
     * @return array|bool|null
     */
    public function codeToId($branchCode,$brand='')
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/codeToId';
            $param['BranchCode'] = $branchCode;
            if(!empty($brand))
                $param['brand'] = $brand;
            return $this->get($url, $param);
        }
        else
            return [];
    }

    /**
     * 返回sto指定网点编号所属的独立网点
     * @param $branchCode 网点编号
     * @return bool|null|string
     */
    public function getStoParentBranchByCode($branchCode)
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/getStoParentBranchByCode';
            $param['BranchCode'] = $branchCode;
            $param['brand'] = 'sto';
            return $this->post($url, $param);
        }
        else
            return '';
    }

    public function isPrimaryBranchById($indexShopId)
    {
        if($indexShopId)
        {
            $url = 'v1/BasicInfo/isPrimaryBranchById';
            $param['index_shop_id'] = $indexShopId;
            return $this->post($url, $param);
        }
        else
            return '';
    }
    public function isPrimaryBranchByCode($branchCode,$brand='')
    {
        if($branchCode)
        {
            $url = 'v1/BasicInfo/isPrimaryBranchByCode';
            $param['BranchCode'] = $branchCode;
            $param['brand'] = $brand;
            return $this->post($url, $param);
        }
        else
            return '';
    }

    /**
     * tbl_branch_list表单条查询
     * @param array $where
     * @return array|bool|null
     */
    public function getOneBranch(array $where)
    {
        if($where)
        {
            $url = 'v1/BasicInfo/getOneBranch';
            $param['where'] = $where;
            return $this->post($url,$param);
        }
        else
            return [];
    }

    /**
     * tbl_branch_list多条查询
     * @param array $where
     * @param string $limit
     * @param string $orderBy
     * @return array|bool|null
     */
    public function getAllBranch(array $where,$limit='',$orderBy='')
    {
        if($where)
        {
            $url = 'v1/BasicInfo/getAllBranch';
            $param['where'] = $where;
            $param['limit'] = $limit;
            $param['orderBy'] = $orderBy;
            return $this->post($url,$param);
        }
        else
            return [];
    }

}